package com.lonely.fx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
 * @date: 2022-07-07 12:52
 * @author: ztkj-hzb
 * @description: 子菜单设置
 **/
public class ChildMenuSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {


        BorderPane borderPane = new BorderPane();

        MenuBar menuBar = new MenuBar();

        borderPane.setTop(menuBar);
        menuBar.setStyle("-fx-background-color: pink");

        Menu menu = new Menu("New");

        MenuItem menuItem1 = new MenuItem("菜单1");
        MenuItem menuItem2 = new MenuItem("菜单2");

        //TODO 设置子菜单，子菜单也是一个Menu,因为Menu继承 MenuItem
        Menu childMenu = new Menu("菜单3");
        MenuItem childMenuItem1 = new MenuItem("子菜单1");
        MenuItem childMenuItem2 = new MenuItem("子菜单2");
        childMenu.getItems().addAll(childMenuItem1, childMenuItem2);


        menu.getItems().addAll(menuItem1, menuItem2, childMenu);

        menuBar.getMenus().add(menu);

        primaryStage.setScene(new Scene(borderPane));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();


    }
}
